<template>
	<view class="shopApplication">
		<view class="boxInfo">
			<view class="disFlex scale-1px-bottom box">
				<view class="left">工厂名称</view>
				<input type="text" v-model="data.factory_name" placeholder="请输入工厂名称" />
			</view>
			<view class="disFlex scale-1px-bottom box">
				<view class="left">联系人姓名</view>
				<input type="text" v-model="data.name" placeholder="请输入联系人姓名" />
			</view>
			<view class="disFlex scale-1px-bottom box">
				<view class="left">工厂地址</view>
				<input type="text" v-model="data.address" placeholder="请输入工厂地址" />
			</view>
			<view class="disFlex  box">
				<view class="left">工厂规模人数</view>
				<input type="text" v-model="data.number" placeholder="请输入工厂规模人数" />
			</view>
		</view>
		<view class="box10">
			<view class="boxInfo">
				<view class="disFlex scale-1px-bottom box">
					<view class="left">手机号</view>
					<input type="text" v-model="data.phone" placeholder="请输入手机号" />
				</view>
				<view class="disFlex btnBox">
					<input type="number" maxlength="6" v-model="code" placeholder="请输入短信验证码"/>
					<button type="default" :disabled="disabled" @tap="getcode">{{disabled?`${time}s后重新获取`:'获取验证码'}}</button>
				</view>
			</view>
		</view>
		<view class="box10">
			<view class="cardBox">
				<view class="title">上传身份证正反面</view>
				<view class="cards disFlex">
					<view class="cardZheng" v-for="(v,i) in img" :key='i' @tap="upimg('0')">
						<image :src="v" mode=""></image>
					</view>
					<view class="cardZheng"  @tap="upimg('add')" v-if="img.length==1?true:false">
						<image src="../../../static/img/add.png" mode=""></image>
					</view>
				</view>
				<view class="explain">*仅用于平台资质审核，以及招标方决策参考，不公开显示。</view>
			</view>
		</view>
		
		
		<view class="box10">
			<view class="LicenseBox">
				<view class="title">上传营业执照</view>
				<view class="imgBox" @tap="upimg('1')">
					<image class="pic" :src="addimg" mode=""></image>
				</view>
				<view class="explain">*仅用于平台资质审核，以及招标方决策参考，不公开显示。</view>
			</view>
		</view>
		<view class="box10">
			<view class="LicenseBox">
				<view class="title">以往经典案例</view>
				<view class="imgBox" @tap="upimg('2')">
					<image class="pic" :src="picimg" mode=""></image>
				</view>
			</view>
		</view>
		
		
		<view class="bottom">
			<button @tap="save()">提交审核</button>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				iscode:'',
				code:'',
				disabled:false,
				time:60,
				img:['../../../static/img/card1.png','../../../static/img/card2.png'],
				addimg:'../../../static/img/add.png',
				picimg:'../../../static/img/add.png',
				data:{
					factory_name:'',
					name:'',
					address:'',
					number:'',
					phone:'',
					idcard:'',
					license:'',
					case:''
				},
			}
		},
		onLoad(option) {
			if(option.type!=0){
				// this.getinfo()
			}
		},
		methods: {
			getinfo(){
				this.http('/api/user/factoryInfo', 'post',{})
					.then((res) => {
						this.data=res.data
						let items=res.data.idcard[0]
						let reg = /\\/g;
						this.img[0] = items.replace(reg,'');
						let items1=res.data.idcard[1]
						this.img[1] = items1.replace(reg,'');
						this.addimg=res.data.license
						this.picimg=res.data.case
					})
			},
			getcode(){
				if(this.data.phone.length==11){
					this.disabled=true
					let dateid=setInterval(()=>{
						if(this.time>1){
							this.time--
						}else{
							clearInterval(dateid)
							this.time=60
							this.disabled=false
						}
					},1000)
					let codedata = {
						phone:this.data.phone,
						type:4,
					}
					this.http('/api/user/send_code', 'post',codedata , )
						.then((res) => {
							if(res.sta==200){
								this.iscode=res.data.code
								console.log(this.iscode)
								uni.showToast({
									title:res.msg,
									icon:'none'
								})
							}else{
								uni.showToast({
									title:res.msg,
									icon:'none'
								})
							}
						})
				}else{
					uni.showToast({
						title:'请输入正确的手机号',
						icon:'none'
					})
				}
			},
			
			upimg(type){
				let token = uni.getStorageSync('userinfo').token
				let user_id = uni.getStorageSync('userinfo').id
				uni.chooseImage({
					count: 2,
					success: res => {
						for(let i=0;i<res.tempFilePaths.length;i++){
							uni.uploadFile({
								url: 'https://admin.51zhandashi.com/api/common/upload_qiniu',
								filePath: res.tempFilePaths[i],
								name: 'upfile',
								formData:{
									token:token,
									user_id:user_id,
									filename:'upfile'
								},
								success: (e) => {
									let v=JSON.parse(e.data)
									if(v.sta==200){
										if(type==0){
											if(this.img.length==2){
												this.img=[]
											}
											this.img.push(v.data.url)
										}else if(type==1){
											this.addimg=v.data.url
										}else if(type==2){
											this.picimg=v.data.url
										}else if(type=='add'&&this.img.length==1){
											this.img.push(v.data.url)
										}
									}
									
									
								}
											
							});
						}
					}
				})
			},
			
			save(){
				this.data.idcard=this.img.toString(',');
				this.data.license=this.addimg
				this.data.case=this.picimg
				
				if(this.data.name==''){
					uni.showToast({
						title:'请输入联系人姓名',
						icon:'none'
					})
					return
				}
				
				if(this.data.phone.length!=11){
					uni.showToast({
						title:'请输入正确的手机号',
						icon:'none'
					})
					return
				}
				if(this.data.idcard=='../../../static/img/card1.png,../../../static/img/card2.png'){
					uni.showToast({
						title:'请输上传身份证照片',
						icon:'none'
					})
					return
				}
				
				if(this.code==''){
					uni.showToast({
						title:'请输入验证码',
						icon:'none'
					})
				}else if(this.iscode==this.code){
					this.http('/api/factory/save', 'post',this.data , )
						.then((res) => {
							if(res.sta==1){
							uni.switchTab({
							    url: '/pages/tabbar/mine'
							});
								uni.showToast({
									title:'提交成功',
									icon:'none'
								})
							}else{
								uni.showToast({
									title:res.msg,
									icon:'none'
								})
							}
						})
				}else{
					uni.showToast({
						title:'验证码有误',
						icon:'none'
					})
				}
			}
		}
	}
</script>

<style lang="less">
	.shopApplication{
		padding-bottom: 200rpx;
		.boxInfo{
			background-color: #fff;
			padding: 0 40rpx;
			.title{
				padding: 35rpx 0 25rpx 0;
				font-size:36rpx;
				font-weight:bold
			}
			.box{
				padding: 35rpx 0;
				.left{
					font-size:32rpx;
				}
				.right{
					color: #BEC9D7;
				}
				.cBox{
					display: flex;
					align-items: center;
					.text{
						color: #BEC9D7;
						padding-right: 26rpx;
					}
					.copy{
						width: 30rpx;
						height: 34rpx;
					}
				}
				input{
					text-align: right;
					color: #BEC9D7;
				}
			}
			.btnBox{
				padding: 35rpx 0;
				input{
					padding-right: 20rpx;
				}
				button{
					color: #2291FF;
					border: none;
					outline: none;
					border-radius: 0;
					background-color: #fff !important;
				}
			}
		}
		.cardBox{
			padding: 35rpx 30rpx 40rpx 40rpx;
			.title{
				font-size: 32rpx;
			}
			.cards{
				margin-top: 36rpx;
				>view{
					width: 325rpx;
					height: 220rpx;
					padding: 34rpx 42rpx;
					box-sizing: border-box;
					background:rgba(245,245,249,1);
					border-radius:10rpx;
					image{
						width: 100%;
						height: 100%;
					}
				}
			}
			.explain{
				padding-top: 25rpx;
				color: #CED3DD;
				font-size: 24rpx;
			}
		}
		.LicenseBox{
			padding: 35rpx 30rpx 40rpx 40rpx;
			.title{
				font-size: 32rpx;
			}
			.imgBox{
				margin-top: 36rpx;
				height:400rpx;
				background:rgba(245,245,249,1);
				border-radius:10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				.add{
					width: 150rpx;
					height: 150rpx;
				}
				.pic{
					width: 100%;
					height: 100%;
					border-radius:10rpx;
				}
			}
			.explain{
				padding-top: 25rpx;
				color: #CED3DD;
				font-size: 24rpx;
			}
		}
		
		
		.bottom{
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 90rpx;
			padding: 0 40rpx;
			z-index: 99;
			button{
				width: 100%;
				line-height: 90rpx;
				background:rgba(34,145,255,1) !important;
				border-radius:10rpx;
				color: #fff;
				font-size: 32rpx;
			}
		}
		
	}
</style>
